package com.example.payment.controller;

import com.example.common.resp.GlobalResult;
import com.example.payment.service.HystrixService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@Slf4j
@RestController
@RequestMapping("/hystrix")
public class HystrixController {

    @Resource
    private HystrixService hystrixService;

    @GetMapping(value = "/success")
    public GlobalResult<String> success() {
        String result = hystrixService.success();
        log.info("*******result: {}", result);
        return GlobalResult.success(result);
    }

    @GetMapping(value = "/timeout")
    public GlobalResult<String> timeout() {
        String result = hystrixService.timeout();
        log.info("*******result: {}", result);
        return GlobalResult.success(result);
    }

    @GetMapping(value = "/circuit/breaker/{id}")
    public GlobalResult<String> circuitBreaker(@PathVariable("id") Long id) {
        String result = hystrixService.circuitBreaker(id);
        log.info("*******result: {}", result);
        return GlobalResult.success(result);
    }
}
